package com.ruoyi.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysPatrol;
import com.ruoyi.project.system.service.ISysPatrolService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 巡查Controller
 * 
 * @author jjp
 * @date 2020-03-30
 */
@RestController
@RequestMapping("/system/patrol")
public class SysPatrolController extends BaseController
{
    @Autowired
    private ISysPatrolService sysPatrolService;

    /**
     * 查询巡查列表
     */
    @PreAuthorize("@ss.hasPermi('system:patrol:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysPatrol sysPatrol)
    {
        startPage();
        List<SysPatrol> list = sysPatrolService.selectSysPatrolList(sysPatrol);
        return getDataTable(list);
    }
    /**
     * 获取巡查详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:patrol:query')")
    @GetMapping(value = "/{patrolId}")
    public AjaxResult getInfo(@PathVariable("patrolId") Long patrolId)
    {
        return AjaxResult.success(sysPatrolService.selectSysPatrolById(patrolId));
    }

    /**
     * 新增巡查
     */
    @PreAuthorize("@ss.hasPermi('system:patrol:add')")
    @Log(title = "巡查", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPatrol sysPatrol)
    {
        return toAjax(sysPatrolService.insertSysPatrol(sysPatrol));
    }

    /**
     * 修改巡查
     */
    @PreAuthorize("@ss.hasPermi('system:patrol:edit')")
    @Log(title = "巡查", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPatrol sysPatrol)
    {
        return toAjax(sysPatrolService.updateSysPatrol(sysPatrol));
    }

    /**
     * 删除巡查
     */
    @PreAuthorize("@ss.hasPermi('system:patrol:remove')")
    @Log(title = "巡查", businessType = BusinessType.DELETE)
	@DeleteMapping("/{patrolIds}")
    public AjaxResult remove(@PathVariable Long[] patrolIds)
    {
        return toAjax(sysPatrolService.deleteSysPatrolByIds(patrolIds));
    }
}
